#include "MapiCE.h"

EXTERN_C MapiCE* MapiLogin(LPCTSTR MsgStore)
{
	if(MsgStore==NULL ||_tcslen(MsgStore)==0)
	{
		MessageBox(NULL,L"Invalid MsgStore,Error Code 1", L"MsgStore", MB_OK);
		return NULL;
	}
	MapiCE* pMapi=new MapiCE();
	if(pMapi==NULL)
	{
		MessageBox(NULL,L"Low on Memory, Error Code 2", L"MapiCE", MB_OK);
		return NULL;
	}
	if(!(pMapi->MAPILogOn()))
	{
		MessageBox(NULL,L"Unable to login, Error Code 3", L"Login", MB_OK);
		pMapi->MAPILogoff();
		delete pMapi;
	}
	else
	{
		if(FAILED(pMapi->GetMsgStore(MsgStore)))
		{
			MessageBox(NULL,L"Unable to open MsgStore, Error Code 4", L"MsgStore", MB_OK);
			pMapi->MAPILogoff();
			delete pMapi;
			pMapi = NULL;
		}
		else
		{
			if(FAILED(pMapi->GetInboxFolder()))
			{
				MessageBox(NULL,L"Unable to getInbox, Error Code 5", L"Inbox", MB_OK);
				pMapi->MAPILogoff();
				delete pMapi;
				pMapi = NULL;
			}
			else
			{
				if(FAILED(pMapi->GetContentTable()))
				{
					MessageBox(NULL,L"Unable to get ContentTable", L"ContentTable", MB_OK);
					pMapi->MAPILogoff();
					delete pMapi;
					pMapi = NULL;
				}
			}
		}
	}
	return pMapi;
}

EXTERN_C bool MapiLogout(MapiCE* pMapi)
{
	if(pMapi!=NULL)
	{
		pMapi->MAPILogoff();
		delete pMapi;
		return true;
	}
	else
		return false;
}

EXTERN_C bool GetNextMessage(MapiCE* pMapi,const FILETIME LastReadTime,WCHAR *mBody,WCHAR *mNumber,FILETIME *mReceivedOn, bool mDelete)
{
	if(pMapi==NULL) return false;
	return (pMapi->GetNextMessage(LastReadTime,mBody,mNumber,mReceivedOn,mDelete));
}


